package com.alameda.controller.user;

import com.alameda.api.user.UserOrganizationService;
import com.alameda.result.Result;
import com.alameda.user.dto.UserOrganizationDTO;
import com.alameda.user.pojo.UserOrganizationDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户组织 前端控制层
 *
 * @author Lv
 * @date 2024/04/27
 */
@Api(tags = "用户组织")
@RestController
@RequestMapping("/user_organization")
public class UserOrganizationController {

    @Autowired
    private UserOrganizationService userOrganizationService;

    /**
     * 查询组织列表
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     * @return
     */
    @ApiOperation("查询组织列表")
    @PostMapping("/list_organization")
    public Result<?> listOrganization(@RequestBody UserOrganizationDTO userOrganizationDTO) {
        return Result.success(userOrganizationService.listOrganization(userOrganizationDTO));
    }

    /**
     * 新增或修改组织
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     * @return
     */
    @ApiOperation("新增或修改组织")
    @PostMapping("/save_or_update")
    public Result<?> saveOrUpdateOrganization(@RequestBody UserOrganizationDTO userOrganizationDTO) {
        return Result.success(userOrganizationService.saveOrUpdateOrganization(userOrganizationDTO));
    }

    /**
     * 导出excel
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     */
    @ApiOperation("导出excel")
    @PostMapping("/export")
    public void export(@RequestBody UserOrganizationDTO userOrganizationDTO) {
        userOrganizationService.export(userOrganizationDTO);
    }

    /**
     * 获取一级组织信息
     *
     * @param userOrganizationDTO 用户组织数据传递对象
     * @return
     */
    @ApiOperation("查询部门信息下拉列表")
    @PostMapping("/find_organization")
    public Result<?> findUserOrganization(@RequestBody UserOrganizationDTO userOrganizationDTO) {
        return Result.success(userOrganizationService.findUserOrganization(userOrganizationDTO));
    }

    /**
     * 删除组织信息
     *
     * @param idList 组织id集合
     * @return
     */
    @ApiOperation("删除组织信息")
    @PostMapping("/delete")
    public Result<?> deleteByIds(@RequestBody List<Long> idList) {
        return Result.success(userOrganizationService.deleteByIds(idList));
    }
}

